package com.jokins.admin.ios.sections.action;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.jokins.admin.ios.sections.actioncontext.GetSectionsListDoc;
import com.jokins.admin.ios.sections.mapper.BookSectionMapper;
import com.jokins.admin.ios.sections.vo.BookSectionVo;
import com.jokins.admin.vue.user.vo.SysUserVo;
import com.jokins.common.actions.action.ActionContext;
import com.jokins.common.actions.action.BaseAction;
import com.jokins.common.actions.exception.BusinessException;
import com.jokins.common.entry.ios.articles.BookSection;
import com.jokins.common.entry.vue.user.SysUser;
import com.jokins.common.util.SqlTypeConverter;
import com.jokins.common.util.date.DateFormatter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 〈〉<br>
 *
 * @author Mr.Wang
 * @create 2025/2/7
 */
@Slf4j
@Component
public class GetSectionsListDocAction extends BaseAction<GetSectionsListDoc> {

    @Autowired
    BookSectionMapper bookSectionMapper;


    @Override
    protected void process(GetSectionsListDoc actionContext) throws BusinessException {
        LambdaQueryWrapper<BookSection> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BookSection::getDeleted,0);
        List<BookSectionVo> bookSectionVoList=new ArrayList<>();
        List<BookSection> bookSectionList = bookSectionMapper.selectList(queryWrapper);
        for (BookSection bookSection : bookSectionList) {
            BookSectionVo vo=new BookSectionVo();
            SqlTypeConverter.convertEntity(bookSection,vo, DateFormatter.DATE_FORMAT_YYYY_MM_DD_HH_MM_SS);
            bookSectionVoList.add(vo);
        }
        log.info("查询板块信息:{}", JSON.toJSONString(bookSectionVoList));
        actionContext.setResult(ActionContext.RESULT_DOC_KEY,bookSectionVoList);
    }
}